using ASP;
using HoWave.Common;
using HoWave.Data.Bll;
using HoWave.Web.Admin;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
using Wuqi.Webdiyer;
public class Admin_MBF_UserGiftCardManage : Admin, IRequiresSessionState
{
	protected DropDownList DropType;
	protected TextBox txtFaceValueQuery;
	protected TextBox txtPurchaseUserNameQuery;
	protected DropDownList ddl_state;
	protected TextBox begindate;
	protected TextBox EndDate;
	protected Button Button1;
	protected GridView GridView1;
	protected AspNetPager AspNetPager1;
	private bool hasGiftCardPower = false;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		this.hasGiftCardPower = base.admin.CheckAdminPower(39);
		if (!base.IsPostBack)
		{
			if (!this.hasGiftCardPower)
			{
				base.WriteLog("Modidy", Language.GetAdminMsg("Log/Access", "0"), "UserGiftCardManage");
				base.WriteRightErrMsg();
			}
			this.DropType.bindTableToDropDownList(Blls.bllFestival.GetDropDownListData(""), false, true);
			this.BindList();
		}
		this.begindate.Attributes.Add("onclick", "SelectDate(" + this.begindate.UniqueID + ",'yyyy-MM-dd');");
		this.EndDate.Attributes.Add("onclick", "SelectDate(" + this.EndDate.UniqueID + ",'yyyy-MM-dd');");
	}
	protected string GetQuestString()
	{
		string text = "";
		string text2 = this.txtPurchaseUserNameQuery.Text.Trim().Replace(" ", "");
		if (text2 != "")
		{
			string commandText = string.Format("select top 1 UserID from HL_User where UserName='{0}'", text2);
			string text3 = this.conn.GetScalar(commandText, new IDbDataParameter[0]).IsNull(new object[0]);
			if (text3 != "")
			{
				text = " BuyID=" + text3 + " ";
			}
			else
			{
				this.txtPurchaseUserNameQuery.Text = "";
				text = " BuyID= 0 ";
			}
		}
		string selectValue = this.DropType.GetSelectValue(new string[0]);
		if (selectValue != "")
		{
			text += string.Format(" and FestivalName='{0}' ", selectValue);
		}
		string text4 = this.txtFaceValueQuery.Text.Trim();
		if (text4 != "")
		{
			decimal d = 0m;
			decimal.TryParse(text4, out d);
			if (d != 0m)
			{
				text += string.Format(" and FaceValue={0} ", text4);
			}
		}
		string text5 = this.begindate.Text;
		if (text5 != string.Empty)
		{
			try
			{
				Convert.ToDateTime(text5);
			}
			catch
			{
				this.WriteErrMsg("", Language.Get("Common/DateTimeFormatErr"), "");
			}
			text = text + " and datediff(dd,BuyTime,'" + text5 + "') <= 0 ";
		}
		string text6 = this.EndDate.Text;
		if (text6 != string.Empty)
		{
			try
			{
				Convert.ToDateTime(text6);
			}
			catch
			{
				this.WriteErrMsg("", Language.Get("Common/DateTimeFormatErr"), "");
			}
			if (!string.IsNullOrEmpty(text5) && Convert.ToDateTime(text6) < Convert.ToDateTime(text5))
			{
				this.WriteErrMsg("", Language.Get("Common/DateTimeErr"), "");
			}
			text = text + " and datediff(dd,BuyTime,'" + text6 + "') >= 0 ";
		}
		string selectValue2 = this.ddl_state.GetSelectValue(new string[0]);
		if (selectValue2 != "")
		{
			if (selectValue2 == "1")
			{
				text += string.Format(" and Balance > 0 ", new object[0]);
			}
			else
			{
				text += string.Format(" and Balance = 0 ", new object[0]);
			}
		}
		string text7 = text.TrimStart(new char[0]).TrimStart("and".ToCharArray());
		if (text7 != "")
		{
			text7 = "(" + text7 + ")";
		}
		return text7;
	}
	protected void GridView1_DataBound(object sender, EventArgs e)
	{
		foreach (GridViewRow gridViewRow in this.GridView1.Rows)
		{
			gridViewRow.Attributes.Add("onmouseover", "cc(this)");
			gridViewRow.Attributes.Add("onmouseout", "cc1(this)");
		}
	}
	protected string GetCategoryName(object obj)
	{
		return Blls.bllUserCardCategory.GetNameByCategory(obj);
	}
	protected string GetUserName(object obj)
	{
		string result;
		if (obj.IsNull(new object[0]) == "" || obj.IsNull(new object[0]) == "0")
		{
			result = "";
		}
		else
		{
			string text = Conn.GetSingle("select top 1 UserName from HL_User where UserID=" + obj.IsNull(new object[0]), new IDbDataParameter[0]).IsNull(new object[0]);
			result = ((text == "") ? "此用户已删除" : text);
		}
		return result;
	}
	protected string GetState(object obj)
	{
		decimal d = obj.ToDecimal2();
		string result;
		if (d != 0m)
		{
			result = "<span color='green'>有余额</span>";
		}
		else
		{
			result = "<span color='red'>无余额</span>";
		}
		return result;
	}
	protected void Query_SelectedIndexChanged(object sender, EventArgs e)
	{
		this.Button1_OnClick(sender, e);
	}
	protected void BindList()
	{
		int num = Fetch.GetID("page");
		if (num <= 0)
		{
			num = 1;
		}
		int pageSize = 20;
		DataSet ds = Blls.bllGiftCard.PageOrderList(pageSize, num, "CardNumber", 1, this.GetQuestString());
		StaticFunApp.AspNetPage(num, pageSize, ds, this.GridView1, this.AspNetPager1);
	}
	protected void Button1_OnClick(object sender, EventArgs e)
	{
		this.BindList();
	}
	protected string DisplayPwd(object o_pwd, object o_buyid, object o_receiveid)
	{
		int num = o_buyid.IsNull(new object[0]).ToInt32(new int[0]);
		int num2 = o_receiveid.IsNull(new object[0]).ToInt32(new int[0]);
		string text = o_pwd.IsNull(new object[0]);
		string result;
		if (!base.admin.CheckAdminPower(39))
		{
			result = "";
		}
		else
		{
			result = text;
		}
		return result;
	}
}
